package model

import (
	"gorm.io/gorm"
	__ "video-srv/basic/proto/rpc"
)

type Comment struct {
	gorm.Model
	VideoId      int    `gorm:"type:int" json:"videoId"`
	UserId       int    `gorm:"type:int" json:"userId"`
	Content      string `gorm:"type:varchar(30)" json:"content"`
	Pid          int    `gorm:"type:int" json:"pid"`
	LikeCount    int    `gorm:"type:int" json:"likeCount"`
	CommentCount int    `gorm:"type:int" json:"commentCount"`
}

func (c *Comment) AddComment(db *gorm.DB) error {
	return db.Create(&c).Error
}

func (c *Comment) GetComment(db *gorm.DB, videoId int) (list []*__.CommentList, err error) {
	err = db.Model(&c).
		Select("username,content,like_count,comment_count").
		Joins("left join videos on videos.id = comments.video_id").
		Joins("left join users on users.id = comments.user_id").
		Where("comments.video_id = ?", videoId).Find(&list).Error
	return
}
